@im-nobsidian/core 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -2,6 +2,26 @@ import { z } from 'zod';
2
2
  import { Client } from '@notionhq/client';
3
3
  import { PageObjectResponse, BlockObjectResponse, PageMarkdownResponse, PartialBlockObjectResponse } from '@notionhq/client/build/src/api-endpoints.js';
4
4
 
5
+ declare const DatabaseSyncSchema: z.ZodObject<{
6
+ databaseId: z.ZodString;
7
+ localFolder: z.ZodString;
8
+ propertyMapping: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
9
+ pullFilter: z.ZodOptional<z.ZodUnknown>;
10
+ titleProperty: z.ZodDefault<z.ZodString>;
11
+ }, "strip", z.ZodTypeAny, {
12
+ databaseId: string;
13
+ localFolder: string;
14
+ titleProperty: string;
15
+ propertyMapping?: Record<string, string> | undefined;
16
+ pullFilter?: unknown;
17
+ }, {
18
+ databaseId: string;
19
+ localFolder: string;
20
+ propertyMapping?: Record<string, string> | undefined;
21
+ pullFilter?: unknown;
22
+ titleProperty?: string | undefined;
23
+ }>;
24
+ type DatabaseSyncConfig = z.infer<typeof DatabaseSyncSchema>;
5
25
  declare const ConfigSchema: z.ZodObject<{
6
26
  version: z.ZodLiteral<1>;
7
27
  notion: z.ZodObject<{
@@ -10,18 +30,51 @@ declare const ConfigSchema: z.ZodObject<{
10
30
  workspaceId: z.ZodOptional<z.ZodString>;
11
31
  parentMode: z.ZodDefault<z.ZodEnum<["page", "database"]>>;
12
32
  databaseId: z.ZodOptional<z.ZodString>;
33
+ databases: z.ZodDefault<z.ZodArray<z.ZodObject<{
34
+ databaseId: z.ZodString;
35
+ localFolder: z.ZodString;
36
+ propertyMapping: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
37
+ pullFilter: z.ZodOptional<z.ZodUnknown>;
38
+ titleProperty: z.ZodDefault<z.ZodString>;
39
+ }, "strip", z.ZodTypeAny, {
40
+ databaseId: string;
41
+ localFolder: string;
42
+ titleProperty: string;
43
+ propertyMapping?: Record<string, string> | undefined;
44
+ pullFilter?: unknown;
45
+ }, {
46
+ databaseId: string;
47
+ localFolder: string;
48
+ propertyMapping?: Record<string, string> | undefined;
49
+ pullFilter?: unknown;
50
+ titleProperty?: string | undefined;
51
+ }>, "many">>;
13
52
  }, "strip", z.ZodTypeAny, {
14
53
  token: string;
15
54
  rootPageId: string;
16
55
  parentMode: "page" | "database";
17
- workspaceId?: string | undefined;
56
+ databases: {
57
+ databaseId: string;
58
+ localFolder: string;
59
+ titleProperty: string;
60
+ propertyMapping?: Record<string, string> | undefined;
61
+ pullFilter?: unknown;
62
+ }[];
18
63
  databaseId?: string | undefined;
64
+ workspaceId?: string | undefined;
19
65
  }, {
20
66
  token: string;
21
67
  rootPageId: string;
68
+ databaseId?: string | undefined;
22
69
  workspaceId?: string | undefined;
23
70
  parentMode?: "page" | "database" | undefined;
24
- databaseId?: string | undefined;
71
+ databases?: {
72
+ databaseId: string;
73
+ localFolder: string;
74
+ propertyMapping?: Record<string, string> | undefined;
75
+ pullFilter?: unknown;
76
+ titleProperty?: string | undefined;
77
+ }[] | undefined;
25
78
  }>;
26
79
  sync: z.ZodObject<{
27
80
  direction: z.ZodDefault<z.ZodEnum<["push", "pull", "both"]>>;
@@ -29,18 +82,21 @@ declare const ConfigSchema: z.ZodObject<{
29
82
  autoSync: z.ZodDefault<z.ZodBoolean>;
30
83
  autoSyncInterval: z.ZodDefault<z.ZodNumber>;
31
84
  deleteSync: z.ZodDefault<z.ZodBoolean>;
85
+ syncFiles: z.ZodDefault<z.ZodBoolean>;
32
86
  }, "strip", z.ZodTypeAny, {
33
87
  direction: "push" | "pull" | "both";
34
88
  conflictStrategy: "local-first" | "remote-first" | "manual" | "duplicate";
35
89
  autoSync: boolean;
36
90
  autoSyncInterval: number;
37
91
  deleteSync: boolean;
92
+ syncFiles: boolean;
38
93
  }, {
39
94
  direction?: "push" | "pull" | "both" | undefined;
40
95
  conflictStrategy?: "local-first" | "remote-first" | "manual" | "duplicate" | undefined;
41
96
  autoSync?: boolean | undefined;
42
97
  autoSyncInterval?: number | undefined;
43
98
  deleteSync?: boolean | undefined;
99
+ syncFiles?: boolean | undefined;
44
100
  }>;
45
101
  paths: z.ZodObject<{
46
102
  include: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
@@ -93,8 +149,15 @@ declare const ConfigSchema: z.ZodObject<{
93
149
  token: string;
94
150
  rootPageId: string;
95
151
  parentMode: "page" | "database";
96
- workspaceId?: string | undefined;
152
+ databases: {
153
+ databaseId: string;
154
+ localFolder: string;
155
+ titleProperty: string;
156
+ propertyMapping?: Record<string, string> | undefined;
157
+ pullFilter?: unknown;
158
+ }[];
97
159
  databaseId?: string | undefined;
160
+ workspaceId?: string | undefined;
98
161
  };
99
162
  sync: {
100
163
  direction: "push" | "pull" | "both";
@@ -102,6 +165,7 @@ declare const ConfigSchema: z.ZodObject<{
102
165
  autoSync: boolean;
103
166
  autoSyncInterval: number;
104
167
  deleteSync: boolean;
168
+ syncFiles: boolean;
105
169
  };
106
170
  paths: {
107
171
  include: string[];
@@ -125,9 +189,16 @@ declare const ConfigSchema: z.ZodObject<{
125
189
  notion: {
126
190
  token: string;
127
191
  rootPageId: string;
192
+ databaseId?: string | undefined;
128
193
  workspaceId?: string | undefined;
129
194
  parentMode?: "page" | "database" | undefined;
130
- databaseId?: string | undefined;
195
+ databases?: {
196
+ databaseId: string;
197
+ localFolder: string;
198
+ propertyMapping?: Record<string, string> | undefined;
199
+ pullFilter?: unknown;
200
+ titleProperty?: string | undefined;
201
+ }[] | undefined;
131
202
  };
132
203
  sync: {
133
204
  direction?: "push" | "pull" | "both" | undefined;
@@ -135,6 +206,7 @@ declare const ConfigSchema: z.ZodObject<{
135
206
  autoSync?: boolean | undefined;
136
207
  autoSyncInterval?: number | undefined;
137
208
  deleteSync?: boolean | undefined;
209
+ syncFiles?: boolean | undefined;
138
210
  };
139
211
  paths: {
140
212
  include?: string[] | undefined;
@@ -347,6 +419,12 @@ declare class StateDB {
347
419
  upsertWikilink(entry: WikilinkEntry): void;
348
420
  getMeta(key: string): string | null;
349
421
  setMeta(key: string, value: string): void;
422
+ isFileRegistered(localPath: string): boolean;
423
+ getFileRegistry(localPath: string): FileRegistryEntry | null;
424
+ getFilesByPageId(notionPageId: string): FileRegistryEntry[];
425
+ registerFile(entry: RegisterFileInput): void;
426
+ deleteFileRegistry(localPath: string): void;
427
+ private mapFileRegistryRow;
350
428
  storePreserveMarkers(path: string, markers: PreserveMarker[]): void;
351
429
  getPreserveMarkers(path: string): PreserveMarker[];
352
430
  transaction<T>(fn: () => T): T;
@@ -365,6 +443,23 @@ interface UpsertSyncRecord {
365
443
  readonly status: SyncRecord["status"];
366
444
  readonly baseSnapshot?: Buffer | null;
367
445
  }
446
+ interface FileRegistryEntry {
447
+ readonly id: string;
448
+ readonly localPath: string;
449
+ readonly notionPageId: string;
450
+ readonly fileUploadId: string;
451
+ readonly fileType: string;
452
+ readonly fileHash: string;
453
+ readonly fileSize: number;
454
+ }
455
+ interface RegisterFileInput {
456
+ readonly localPath: string;
457
+ readonly notionPageId: string;
458
+ readonly fileUploadId: string;
459
+ readonly fileType: string;
460
+ readonly fileHash: string;
461
+ readonly fileSize: number;
462
+ }
368
463
 
369
464
  interface NotionClientOptions {
370
465
  readonly token: string;
@@ -408,10 +503,13 @@ declare class NotionClient {
408
503
  queryDatabase(databaseId: string, options?: {
409
504
  startCursor?: string;
410
505
  pageSize?: number;
506
+ filter?: unknown;
411
507
  }): Promise<{
412
508
  results: PageObjectResponse[];
413
509
  nextCursor: string | null;
414
510
  }>;
511
+ queryAllDatabasePages(databaseId: string, filter?: unknown): Promise<PageObjectResponse[]>;
512
+ getDataSourceId(databaseId: string): Promise<string>;
415
513
  archivePage(pageId: string): Promise<void>;
416
514
  listChildren(blockId: string, options?: {
417
515
  startCursor?: string;
@@ -580,6 +678,11 @@ declare class ChangeDetector {
580
678
  private detectMoves;
581
679
  }
582
680
 
681
+ interface NonMdFileInfo {
682
+ readonly path: string;
683
+ readonly size: number;
684
+ readonly mtime: string;
685
+ }
583
686
  interface VaultFS {
584
687
  readFile(path: string): Promise<string>;
585
688
  readBinary(path: string): Promise<Buffer>;
@@ -590,6 +693,7 @@ interface VaultFS {
590
693
  exists(path: string): Promise<boolean>;
591
694
  ensureFolder(path: string): Promise<void>;
592
695
  listMarkdownFiles(): Promise<FileInfo[]>;
696
+ listNonMarkdownFiles(): Promise<NonMdFileInfo[]>;
593
697
  }
594
698
 
595
699
  declare class SyncOrchestrator {
@@ -601,6 +705,8 @@ declare class SyncOrchestrator {
601
705
  private readonly pipeline;
602
706
  private readonly blockConverter;
603
707
  private readonly imageHandler;
708
+ private readonly fileHandler;
709
+ private readonly databaseSyncer;
604
710
  private readonly propertyMapper;
605
711
  private dbSchemaLoaded;
606
712
  constructor(config: Config, stateDb: StateDB, notionClient: NotionClient, vaultFs: VaultFS);
@@ -651,8 +757,10 @@ declare class NodeVaultFS implements VaultFS {
651
757
  exists(path: string): Promise<boolean>;
652
758
  ensureFolder(path: string): Promise<void>;
653
759
  listMarkdownFiles(): Promise<FileInfo[]>;
760
+ listNonMarkdownFiles(): Promise<NonMdFileInfo[]>;
654
761
  private matchesPattern;
655
762
  private isExcluded;
763
+ private walkDirNonMd;
656
764
  private walkDir;
657
765
  }
658
766
 
@@ -684,6 +792,37 @@ declare class ImageHandler {
684
792
  private guessExtension;
685
793
  }
686
794
 
795
+ type NotionBlockType = "image" | "pdf" | "video" | "audio" | "file";
796
+ interface FileUploadResult {
797
+ readonly localPath: string;
798
+ readonly fileUploadId: string;
799
+ readonly blockType: NotionBlockType;
800
+ }
801
+ interface FileDownloadResult {
802
+ readonly url: string;
803
+ readonly localPath: string;
804
+ readonly hash: string;
805
+ readonly size: number;
806
+ }
807
+ declare class FileHandler {
808
+ private readonly vaultFs;
809
+ private readonly notionClient;
810
+ private readonly stateDb;
811
+ private readonly sema;
812
+ constructor(vaultFs: VaultFS, notionClient: NotionClient, stateDb: StateDB);
813
+ pushFilesForFolder(folderPageId: string, folderPath: string): Promise<FileUploadResult[]>;
814
+ pushAllFiles(): Promise<FileUploadResult[]>;
815
+ downloadFileBlock(url: string, filename: string, targetFolder: string): Promise<FileDownloadResult>;
816
+ downloadFileBlocks(blocks: Array<{
817
+ type: string;
818
+ url: string;
819
+ caption?: string;
820
+ }>, targetFolder: string): Promise<FileDownloadResult[]>;
821
+ private uploadFile;
822
+ private createFileBlock;
823
+ private extractFilename;
824
+ }
825
+
687
826
  declare class ConversionPipeline {
688
827
  private readonly preProcessors;
689
828
  private readonly postProcessors;
@@ -694,6 +833,27 @@ declare class ConversionPipeline {
694
833
  convertToMarkdown(content: string, context: ConversionContext, metadata?: ProcessorMetadata): string;
695
834
  }
696
835
 
836
+ interface DatabaseSyncResult {
837
+ created: number;
838
+ updated: number;
839
+ failed: FailedOperation[];
840
+ }
841
+ declare class DatabaseSyncer {
842
+ private readonly config;
843
+ private readonly stateDb;
844
+ private readonly notionClient;
845
+ private readonly vaultFs;
846
+ private readonly pipeline;
847
+ private readonly imageHandler;
848
+ private readonly propertyMapper;
849
+ constructor(config: Config, stateDb: StateDB, notionClient: NotionClient, vaultFs: VaultFS, pipeline: ConversionPipeline, imageHandler: ImageHandler);
850
+ pullAll(): Promise<DatabaseSyncResult>;
851
+ pushAll(): Promise<DatabaseSyncResult>;
852
+ private pullDatabase;
853
+ private pullDatabasePage;
854
+ private pushDatabase;
855
+ }
856
+
697
857
  declare class BlockConverter {
698
858
  private n2m;
699
859
  private client;
@@ -984,4 +1144,4 @@ interface PipelineOptions {
984
1144
  }
985
1145
  declare function createDefaultPipeline(options?: PipelineOptions): ConversionPipeline;
986
1146
 
987
- export { BlockConverter, CalloutRestorer, CalloutTransformer, ChangeDetector, ColorAnnotator, type Config, ConfigManager, ConfigSchema, type Conflict, ConflictResolver, type ConflictStrategy, type ConversionContext, type ConversionPath, ConversionPipeline, type ConversionResult, DEFAULT_CONFIG, EmbedResolver, type FailedOperation, type FileInfo, type FileSystemEntry, type FileType, FileWatcher, FrontmatterExtractor, FrontmatterGenerator, HtmlAnnotationStripper, type ImageDownloadResult, ImageHandler, type ImageReference, InlineDBParser, type LocalChange, LocalImageRestorer, type Logger, type MappingResult, type MappingType, MathNormalizer, MentionToWikilink, type MergeConflictRegion, type MergeResult, NodeVaultFS, type NotionBlock, NotionBlockBuilder, NotionClient, type NotionClientOptions, type NotionPageNode, type NotionRichText, type RichTextItem as NotionRichTextItem, type OperationType, type PageCreationPlan, type PathFilterConfig, type PreserveMarker, PreserveMarkerCollector, PreserveMarkerInjector, type Processor, type ProcessorInput, type ProcessorMetadata, type ProcessorOutput, type ProgressCallback, PropertiesTableInjector, PropertiesTableRestorer, PropertyMapper, type PullOptions, type PullResult, type PushOptions, type PushResult, type RemoteChange, type ResolutionChoice, type ResolutionResult, type RichTextSegment, StateDB, type StatusResult, type SyncDirection, type SyncOptions, SyncOrchestrator, type SyncRecord, type SyncResult, type SyncStatus, TreeMapper, UnsupportedBlockStripper, type UpsertSyncRecord, type VaultFS, type WatchSyncOptions, WatchSyncService, type WikilinkEntry, WikilinkResolver, computeBufferHash, computeHash, createDefaultPipeline, generateId, getLogger, normalizeNotionId, notionIdsEqual, sanitizeFileName, setLogger, threeWayMerge };
1147
+ export { BlockConverter, CalloutRestorer, CalloutTransformer, ChangeDetector, ColorAnnotator, type Config, ConfigManager, ConfigSchema, type Conflict, ConflictResolver, type ConflictStrategy, type ConversionContext, type ConversionPath, ConversionPipeline, type ConversionResult, DEFAULT_CONFIG, type DatabaseSyncConfig, type DatabaseSyncResult, DatabaseSyncer, EmbedResolver, type FailedOperation, type FileDownloadResult, FileHandler, type FileInfo, type FileSystemEntry, type FileType, type FileUploadResult, FileWatcher, FrontmatterExtractor, FrontmatterGenerator, HtmlAnnotationStripper, type ImageDownloadResult, ImageHandler, type ImageReference, InlineDBParser, type LocalChange, LocalImageRestorer, type Logger, type MappingResult, type MappingType, MathNormalizer, MentionToWikilink, type MergeConflictRegion, type MergeResult, NodeVaultFS, type NonMdFileInfo, type NotionBlock, NotionBlockBuilder, NotionClient, type NotionClientOptions, type NotionPageNode, type NotionRichText, type RichTextItem as NotionRichTextItem, type OperationType, type PageCreationPlan, type PathFilterConfig, type PreserveMarker, PreserveMarkerCollector, PreserveMarkerInjector, type Processor, type ProcessorInput, type ProcessorMetadata, type ProcessorOutput, type ProgressCallback, PropertiesTableInjector, PropertiesTableRestorer, PropertyMapper, type PullOptions, type PullResult, type PushOptions, type PushResult, type RemoteChange, type ResolutionChoice, type ResolutionResult, type RichTextSegment, StateDB, type StatusResult, type SyncDirection, type SyncOptions, SyncOrchestrator, type SyncRecord, type SyncResult, type SyncStatus, TreeMapper, UnsupportedBlockStripper, type UpsertSyncRecord, type VaultFS, type WatchSyncOptions, WatchSyncService, type WikilinkEntry, WikilinkResolver, computeBufferHash, computeHash, createDefaultPipeline, generateId, getLogger, normalizeNotionId, notionIdsEqual, sanitizeFileName, setLogger, threeWayMerge };